/*
 * ASL.c
 *
 *  Created on: Jan 21, 2014
 *      Author: Rohit
 */

#include "includes.h"

/*
 * Function: func_ASL
 *
	Condition Codes: Z: set if the result = 0; cleared otherwise
	N: set if the high-order bit of the result is set; cleared
	otherwise
	C: loaded with the high-order bit of the destination
	V: loaded with the Exclusive OR of the N-bit and C-bit
	(as set by the completion of the shift operation)
	Description: Shifts all bits of the destination left one place. Bit 0 is loaded
	with a 0. The C-bit of the status word is loaded from the most significant bit
	of the destination. ASL performs a signed multiplication of the destination
	by 2.
 */


void func_ASL(unsigned short address_destination)
{
	unsigned short result;
	unsigned short most_significant_bit;
	unsigned short data_destination;

	data_destination = read_from_memory(address_destination,DATA);

	result = data_destination;

	//Preserving the MSB of the destination
	most_significant_bit = data_destination & 0x8000;

	result = result << 1;

	write_in_memory(address_destination, result,DATA);

	if(most_significant_bit == 0)
		clear_C_flag();
	else
		set_C_flag();

	update_Z_flag(result);

	update_N_flag(ASL, result);

	if(get_C_flag() ^ get_N_flag())
		set_V_flag();
	else
		clear_V_flag();
}


